package com.dailyblue.example.spring.aop.annotation.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class SecondAdvice {
    @Pointcut("execution(* com.dailyblue.example.spring.aop.annotation.target.*.*(..))")
    private void execute(){}

    // 前置通知
    @Before("execution(* com.dailyblue.example.spring.aop.annotation.target.SecondTarget.*(..))")
    public void before(JoinPoint jp) {
        Object[] args = jp.getArgs();
        System.out.println("参数是：" + Arrays.toString(args));
        System.out.println("我是前置通知");
    }
    @AfterReturning("execute()")
    public void afterReturn(JoinPoint jp){
        Object[] args = jp.getArgs();
        System.out.println("参数是：" + Arrays.toString(args));
        System.out.println("我是后置通知");
    }
    @After("execute()")
    public void after(JoinPoint jp){
        Object[] args = jp.getArgs();
        System.out.println("参数是：" + Arrays.toString(args));
        System.out.println("我是最终通知");
    }
    @AfterThrowing("execute()")
    public void exception(){
        System.out.println("我是异常通知");
    }
    @Around("execute()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("我是环绕通知之前");
        Object result = pjp.proceed();
        System.out.println("我是环绕通知之后");
        return result;
    }
}
